package com.jiamao.goplay.adapter;

import android.content.Context;
import android.os.Build;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.LayoutRes;
import androidx.annotation.RequiresApi;
import androidx.databinding.ViewDataBinding;

import com.bumptech.glide.Glide;
import com.discussionavatarview.DiscussionAvatarView;
import com.itheima.roundedimageview.RoundedImageView;
import com.jiamao.goplay.R;
import com.jiamao.goplay.ui.discover.vm.CityMenuItemVM;
import com.jiamao.goplay.ui.discover.vm.NeayByItemVM;
import com.jiamao.goplay.view.DiscussionAvatarViews;
import com.jiamao.goplay.view.PileLayout;

import java.util.ArrayList;

import me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter;

public class NearbyAdapter extends BindingRecyclerViewAdapter {

    Context context;
    LayoutInflater inflater;
    public NearbyAdapter(Context context){
        this.context = context;
         inflater = LayoutInflater.from(context);
    }

    @Override
    public ViewDataBinding onCreateBinding(LayoutInflater inflater, @LayoutRes int layoutId, ViewGroup viewGroup) {
        ViewDataBinding binding = super.onCreateBinding(inflater, layoutId, viewGroup);
        return binding;
    }

    private int iondex = 0 ;

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public void onBindBinding(ViewDataBinding binding, int bindingVariable, @LayoutRes int layoutId, int position, Object item) {
        super.onBindBinding(binding, bindingVariable, layoutId, position, item);
                if (item instanceof NeayByItemVM){

                    NeayByItemVM vm  = (NeayByItemVM) item;

                    //TextView textView = binding.getRoot().findViewById(R.id.tv_goto_btn);

                    //LinearLayout btn_goto = binding.getRoot().findViewById(R.id.btn_goto);



//                   if(vm.status == 1){
//                       textView.setText("已添加");
//                       binding.getRoot().findViewById(R.id.tv_goto_img).setVisibility(View.GONE);
//                       textView.setTextColor(context.getColor(R.color.discover_nearby_goto));
//                   }  else {
//                       textView.setText("想去");
//                       binding.getRoot().findViewById(R.id.tv_goto_img).setVisibility(View.VISIBLE);
//                       textView.setTextColor(context.getColor(R.color.discover_nearby_item_goto));
//                   }
//                    btn_goto.setOnClickListener(new View.OnClickListener() {
//                        @Override
//                        public void onClick(View view) {
//
//                        }
//                    });
                    DiscussionAvatarViews discussionAvatarView = binding.getRoot().findViewById(R.id.pile_layout);
                    discussionAvatarView.initDatas( vm.pig);

//                    if (vm.pig !=null){
//                        for (int i = 0; i <  vm.pig.size(); i++) {
//
//                            RoundedImageView imageView = (RoundedImageView) inflater.inflate(R.layout.user_array_img,discussionAvatarView,false);
//                            Glide.with(context).load( vm.pig.get(i)).into(imageView);
//                            discussionAvatarView.addView(imageView);
//                        }
//
//                    }


                    //binding.getRoot().findViewById(R.id.)

             }
    }

    public void refreshUI(NeayByItemVM vm){

//        CityMenuItemVM vm = (CityMenuItemVM) getAdapterItem(iondex);
//        vm.select.set(false);
//        notifyItemChanged();
////        notifyItemChanged(iondex);
//        notifyDataSetChanged();

    }

//    @Override
//    public void onBindBinding(@NonNull ViewDataBinding binding, int variableId, int layoutRes, int position, Object item) {
//        super.onBindBinding(binding, variableId, layoutRes, position, item);
//
//        if (item instanceof CityMenuItemVM){
//            CityMenuItemVM vm  = (CityMenuItemVM) item;
//
//        }
//
//    }
}
